package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.TextView;

import java.util.List;

import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.model.SubChildrenBean;

/**
 * Created by lenovo on 2016/10/19.
 */

public class RecycleCategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int TYPE1 = 1;
    private static final int TYPE2 = 2;
    private List<Object> lists;
    private LayoutInflater inflater;
    private Context context;
    public RecycleCategoryAdapter(Context context,LayoutInflater inflater,List<Object> lists)
    {
        this.context=context;
        this.inflater =inflater;
        this.context=context;
        this.lists=lists;
    }

    @Override
    public int getItemViewType(int position) {
        if (lists.get(position) instanceof  String)
        {
            return TYPE1;
        }else  if (lists.get(position) instanceof List)
        {
            return TYPE2;
        }
        return 0;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE1)
        {
            View view = inflater.inflate(R.layout.item1_category_recycle, parent, false);
            ViewHolder1 holder1 =new ViewHolder1(view);
            return holder1;
        }else if (viewType == TYPE2){
            View view = inflater.inflate(R.layout.item2_category_recycle, parent, false);
            ViewHolder2 holder2 =new ViewHolder2(view);
            return holder2;
        }
        return  null;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
          if (holder instanceof ViewHolder1)
          {
              String name = (String) lists.get(position);
              ((ViewHolder1) holder).textView_name.setText(name);
          }else if (holder instanceof ViewHolder2)
          {
              List<SubChildrenBean> bean = (List<SubChildrenBean>) lists.get(position);

              GridCategoryAdapter adapter =new GridCategoryAdapter(context,bean,inflater);



              ((ViewHolder2) holder).gridView.setAdapter(adapter);
          }
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }
    class ViewHolder1 extends RecyclerView.ViewHolder

    {
        TextView textView_name;

        public ViewHolder1(View itemView) {
            super(itemView);
           textView_name = (TextView) itemView.findViewById(R.id.item1_textView_category);
        }
    }
    class  ViewHolder2 extends RecyclerView.ViewHolder
    {
        GridView gridView;

        public ViewHolder2(View itemView) {
            super(itemView);
            gridView = (GridView) itemView.findViewById(R.id.item2_gridview_category);
        }
    }
}
